package com.ay.weixin.fdc.admin.customer.db;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lizar.db.ibatis.Dao;

import com.ay.weixin.fdc.admin.customer.domain.WeiXinProject;
import com.ay.weixin.fdc.admin.customer.domain.WeiXinProject.WeiXinProjectStatus;

public class IbatisWeiXinProjectDao extends Dao{

	
	public void insert(WeiXinProject project) throws SQLException{
		this.sqlMapper.insert("weixin_project.insert",project);
	}
	
	public boolean name_exists(String name) throws SQLException{
		return this.sqlMapper.queryForObject("weixin_project.name_exists",name)!=null;
	}
	
	public WeiXinProject get(String name) throws SQLException{
		return (WeiXinProject)this.sqlMapper.queryForObject("weixin_project.get",name);
	}
	
	public void update(WeiXinProject project)throws SQLException{
		this.sqlMapper.insert("weixin_project.update",project);
	}
	
	public void delete(long id)throws SQLException{
		this.sqlMapper.insert("weixin_project.delete",id);
	}
	
	public WeiXinProject getById(long id) throws SQLException{
		return (WeiXinProject)this.sqlMapper.queryForObject("weixin_project.getById",id);
	}
	

	
	public List<WeiXinProject> getAllByStatus(WeiXinProjectStatus status) throws SQLException{
		return (List<WeiXinProject>)this.sqlMapper.queryForList("weixin_project.getAllByStatus",status.name());
	}
	
	public List<WeiXinProject> getByStatus(String status,int start,int size) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		map.put("start", start);
		map.put("size", size);
		return (List<WeiXinProject>)this.sqlMapper.queryForList("weixin_project.getByStatus",map);
	}
	
	public List<WeiXinProject> searchByStatus(String status,String keywords,int start,int size) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		map.put("keywords", keywords);
		map.put("start", start);
		map.put("size", size);
		return (List<WeiXinProject>)this.sqlMapper.queryForList("weixin_project.searchByStatus",map);
	}
	
	public int countByStatus(String status) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		Integer count=(Integer) this.sqlMapper.queryForObject("weixin_project.countByStatus",map);
		if(count==null)return 0;
		return count;
	}
	
	public int countSearchByStatus(String status,String keywords) throws SQLException{
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("status", status);
		map.put("keywords", keywords);
		Integer count=(Integer) this.sqlMapper.queryForObject("weixin_project.countSearchByStatus",map);
		if(count==null)return 0;
		return count;
	}
}
